/*
 	Copyright 2007 Amazon Technologies, Inc.  Licensed under the Apache License, Version 2.0 (the "License"); 
	you may not use this file except in compliance with the License. You may obtain a copy of the License at:

	http://aws.amazon.com/apache2.0

	This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
	See the License for the specific language governing permissions and limitations under the License.  
 */

package com.inspectortime.webapp.util.fps;

import org.apache.axis.AxisFault;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.handlers.BasicHandler;
import org.apache.log4j.Logger;

/**
 * This class implements an Axis handler which logs the SOAP requests sent 
 * from the client to FPS and the reponses received from FPS.
 */
public class SOAPPrintHandler extends BasicHandler {

	private static final long serialVersionUID = 1L;

	// Initializing the log4j Logger object.		
	private static Logger log = Logger.getLogger(SOAPPrintHandler.class.getName());

	public void invoke(MessageContext msgCxt) throws AxisFault {
		Message request = msgCxt.getRequestMessage();
		Message response = msgCxt.getResponseMessage();
		
		if (request != null && response == null) {
			log.info("\n\n************SOAP Request: ********\n" + 
				request.getSOAPPartAsString());
		}
		if (response != null) {
			log.info("\n\n***************SOAP Response: *************\n" + 
				response.getSOAPPartAsString());
		}
	}
}
